﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace sy2_99
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Text = "加密";
            textBox1.Multiline = true;
            textBox1.ScrollBars = ScrollBars.Vertical;
        }

        private string Rot13Convert(string input)
        {
            char[] chars = input.ToCharArray();
            for (int i = 0; i < chars.Length; i++)
            {
                char c = chars[i];
                if (c >= 'A' && c <= 'Z')
                {
                    chars[i] = (char)(((c - 'A') + 13) % 26 + 'A');
                }
                else if (c >= 'a' && c <= 'z')
                {
                    chars[i] = (char)(((c - 'a') + 13) % 26 + 'a');
                }
            }
            return new string(chars);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Rot13Convert(textBox1.Text);

            if (button1.Text == "加密")
            {
                button1.Text = "解密";
            }
            else
            {
                button1.Text = "加密";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            button1.Text = "加密";
        }
    }
}
